<?xml version="1.0" encoding="UTF-8"?>
<definitions id="definitions" 
  xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
  xmlns:camunda="http://camunda.org/schema/1.0/bpmn"
  targetNamespace="Examples">
  
  <process id="txProcess" isExecutable="true">

    <startEvent id="start" />
    
    <sequenceFlow sourceRef="start" targetRef="tx" />
    <transaction id="tx">
      <startEvent id="txStart" />
      <sequenceFlow sourceRef="txStart" targetRef="innerSubProcess" />
      
      <subProcess id="innerSubProcess">
        <startEvent id="innerSubProcessStart" />
        <sequenceFlow sourceRef="innerSubProcessStart" targetRef="activity" />
        <serviceTask id="activity" camunda:expression="${true}" />
        <sequenceFlow sourceRef="activity" targetRef="innerSubProcessEnd" />
        <endEvent id="innerSubProcessEnd" />
        
        <!-- compensation event subprocess for scope that re-throws compensation -->
        <subProcess id="eventSubProcess" triggeredByEvent="true">
          <startEvent id="eventSubProcessStart">
            <compensateEventDefinition />
          </startEvent>
          <sequenceFlow sourceRef="eventSubProcessStart" targetRef="eventSubProcessThrowCompensation" />
          <intermediateThrowEvent id="eventSubProcessThrowCompensation">
            <compensateEventDefinition activityRef="activity" />
          </intermediateThrowEvent>
          <sequenceFlow sourceRef="eventSubProcessThrowCompensation" targetRef="eventSubProcessEnd" />
          <endEvent id="eventSubProcessEnd" />
        </subProcess>
      
        <!-- black box compensation handler for "activity" -->
        <boundaryEvent id="compensateBoundaryEvent" attachedToRef="activity">
          <compensateEventDefinition />
        </boundaryEvent>
        <userTask id="blackBoxCompensationHandler" isForCompensation="true"/>
        <association associationDirection="One" sourceRef="compensateBoundaryEvent" targetRef="blackBoxCompensationHandler" />
      </subProcess>
      
      <sequenceFlow sourceRef="innerSubProcess" targetRef="beforeCancelEnd" />
      <userTask id="beforeCancelEnd" />
      <sequenceFlow sourceRef="beforeCancelEnd" targetRef="cancelEnd" />
      <endEvent id="cancelEnd" >
        <cancelEventDefinition id="cancelEndId" />
      </endEvent>
      
      
  
      
    </transaction>
    
    <sequenceFlow sourceRef="tx" targetRef="end"/>
    <endEvent id="end" />
    
    <!-- cancel boundary event -->
    <boundaryEvent attachedToRef="tx" id="catchCancelTx">
      <cancelEventDefinition id="cancel"/>      
    </boundaryEvent>
    <sequenceFlow sourceRef="catchCancelTx" targetRef="cancelled" />
    <endEvent id="cancelled" />
  </process>

</definitions>
